<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>返回数组中指定元素的下标</title>
</head>
<body>
<script>
    var arr = ['a', 'b', 'd', 'd', 'e', 'd', 'd', 'f'];

    function findall(arr, target) {
        var indexe = [];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] === target) {
                indexe.push(i);
            }
        }
        return indexe;
    }
    function count(arr, target) {
        var count = 0;
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] === target) {
                count++;
            }
        }
        return count;
    }

    var target= 'd';
    var allIndex = findall(arr, target);
    var occurrencesCount = count(arr, target);

    document.body.innerHTML = allIndex.join(", ") + "<br>" + occurrencesCount;
</script>
</body>
</html>